package com.konsung.ksdc.manager.community;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.konsung.ksdc.R;
import com.konsung.ksdc.bean.netbean.GroupNetBean;
import com.konsung.ksdc.common.utils.StringUtils;
import com.konsung.ksdc.config.MyApplication;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 创建者     kgh
 * 创建时间   2016/5/27 15:28
 * 更新者     $Author$
 * 更新时间   $Date$
 * 更新描述   ${TODO}
 */
public class GroupListAdapter extends BaseAdapter {
    public List<GroupNetBean> groups;

    /**
     * 构造方法
     * @param groups 集合
     */
    public GroupListAdapter(List<GroupNetBean> groups) {
        this.groups = groups;
    }

    @Override
    public int getCount() {
        return this.groups.size();
    }

    @Override
    public Object getItem(int i) {
        return this.groups.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup container) {
        GroupNetBean group = this.groups.get(position);

        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(MyApplication.getContext())
                    .inflate(R.layout.item_listview_group, null);
            ButterKnife.bind(holder, convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.txtGroupName.setText(group.getGroupName());
        //头像需要拼接
        Glide.with(MyApplication.getContext()).load(StringUtils.appendPicPath(group.getGroupPic()
        )).error(R.drawable.pic_head_defult).crossFade(1000).
                into(holder.imgGroupPic);
        return convertView;
    }

    /**
     * 内部类
     */
    static class ViewHolder {
        @Bind(R.id.img_group_pic)
        ImageView imgGroupPic;
        @Bind(R.id.txt_group_name)
        TextView txtGroupName;
    }
}
